# 1.有一对兔子从出生后3个月开始一个月生一对小兔子，小兔子长到第三个月后每个月又生一对兔子，假如兔子都不死。
# 问每个月的兔子总数是多少？
# 【提示，先画图找出规律，写函数能实现即可（用面向对象的类实现也可以)】

# 方案一：面向对象
# rabbits = []  # 笼子
# 兔子类
# class Rabbit(object):
#     def __init__(self):
#         self.age = 1  # 默认是一个月份
#
#     def bron(self):
#         """出生方法"""
#         if self.age >= 3:  # 月份大于三，就向笼子里放一只新兔子（只有一个月属性的兔子）
#             rabbits.append(Rabbit())  # 放一只兔子到笼子
#
#         self.age += 1  # 生一次月份加一
# # 月份出生类
# class MonthRabbits(object):
#     def __init__(self,month):
#         self.month = month
#         self.month_count = []
#         self.month_bron()
#
#     def month_bron(self):
#         rabbits.append(Rabbit())  # 初始一只兔子
#         """每隔一个月调一次所有兔子的出生方法"""
#         for i in range(self.month):
#             for j in rabbits:  # 循环取兔子
#                 j.bron()
#             # 记录当月有几只兔子
#             self.month_count.append(len(rabbits))  # 当月兔子总数并添加到count
#
# if __name__ == '__main__':
#     m = MonthRabbits(10)
#     print(m.month_count)


# def rabbit(n):
#     a,b=0,1
#     for i in range(n-1):
#         a,b = b,a+b
#     return b

# 方案二：数学推导式：f(n)=1+1+...+(f(n-2)+f(n-1))
# rabbits=[]
# month=12
# for i in range(1,month+1):
#     if i <3:
#         rabbits.append(1)
#     else:
#         rabbits.append(rabbits[-2] + rabbits[-1])
# print(rabbits)

# def fib(n):
#     fib=[]
#     for i in range(1,n+1):
#         if i <3:
#             fib.append(1)
#         else:
#             fib.append(fib[-2]+fib[-1])
#     print(fib)
# fib(10)

# 2.写一个游戏机器人自动游戏比赛，说明:先定义一个基类:AutoPeople，类中存在一个全局类成员。
# 所有队员能出拳GameDic=["石头"，"剪刀"，"布"]，然后定义一个分数值Score。
# 【提示1:如何判断胜负?GameDic中任意下标相减等于-1或⒉就是胜利，否则就是失败﹐等于O就是平手】
# 【提示2:建议用3个类实现全部功能。机器人类，游戏规则类，比赛类】
# 随机出拳:random.randint(0,2) random.choice(["石头"，"剪刀", "布"])

# 用例
# "石头" - "剪刀" = -1    胜
# "石头"  - "布" = -2     负
# "石头"  - "石头" =0     平

#  "剪刀"  - "石头" = 1   负
# "剪刀" - "剪刀" =0      平
# "剪刀" - "布"=-1        胜

#  "布" - "石头" = 2      胜
# "布" - "剪刀" =1        负
# "布"- "布"=0            平

#分析
#1.AutoPeople 类 -- 能记下分数，能出拳
#2.Game 类  -- 根据2个人出的拳，判断谁胜谁负
#3.PlayGame 类 -- 指定谁和谁游戏，指定 局数 ， 能获取结果。
# import random
# class AutoPeople(object):
#     GameDic = ["石头","剪刀","布"]
#     def __init__(self,name):
#         self.name = name
#         self.score = 0
#
#     def add_score(self):
#         """一次加一分"""
#         self.score +=1
#     def show_punch(self):
#         """出拳"""
#         return random.choice(AutoPeople.GameDic)
#     def show_score(self):
#         """展示分数"""
#         print(f'{self.name}:{self.score}')
#
# class Gamerule(object):
#     """只负责规则，判断结果"""
#     @classmethod
#     def get_result(cls,punch1,punch2):
#         """punch1，2：出拳的结果"""
#         result = AutoPeople.GameDic.index(punch1)-AutoPeople.GameDic.index(punch2)
#         if result in (-1,2):
#             return '胜'
#         elif result == 0:
#             return '平'
#         else:
#             return '负'
#
# class PlayGame(object):
#     """指定谁和谁游戏，指定局数，获取结果"""
#     def __init__(self,AutoPeople1,AutoPeople2):
#         self.ap1 = AutoPeople1
#         self.ap2 = AutoPeople2
#
#     def pgame_one(self):
#         """玩一次游戏"""
#         punch1 = self.ap1.show_punch()
#         punch2 = self.ap2.show_punch()
#         result = Gamerule.get_result(punch1,punch2)
#         if result == '胜':
#             self.ap1.add_score()
#         elif result == '负':
#             self.ap2.add_score()
#         print(f"{self.ap1.name}-{punch1} vs {self.ap2.name}-{punch2}: {result}")
#
#     def pgame_many(self, much):
#         """玩多次"""
#         for i in range(much):
#             self.pgame_one()
#
# if __name__ == '__main__':
#     ap1=AutoPeople("张三")
#     ap2=AutoPeople("李四")
#
#     pg=PlayGame(ap1,ap2)
#     pg.pgame_many(5)
#     print(ap1.score)
#     print(ap2.score)

# 3.实现一个函数my_len(object),作用与len(object)相同
# def my_len(object):
#     count = 0
#     for i in object:
#         count += 1
#     return count
#
# a = 'dcfvbnmcvb'
# print(my_len(a))

"""
4.实现一个猫Cat类和狗Dog类，要求猫和狗都有昵称(nickname)和年龄(age)属性，以及抓老鼠(catch_mice)的方法，
  其中猫再抓老鼠时，打印"本职工作"，狗再抓老鼠时，打印"多管闲事"。
"""
# class Animal():
#     def __init__(self,nickname,age):
#         self.nickname = nickname
#         self.age = age
# class Cat(Animal):
#     def catch_mice(self):
#         print(f'{self.nickname}:本职工作')
# class Dog(Animal):
#     def catch_mice(self):
#         print(f'{self.nickname}:多管闲事')
#
# if __name__ == '__main__':
#     c = Cat('花花',2)
#     d = Dog('点点',1)
#     c.catch_mice()
#     d.catch_mice()

"""
7.士兵进行设计训练，统计在1分钟内的开枪次数，总成绩（每一次射击的成绩在8-10环之间）
  （1）枪的弹夹容量为10，子弹打完后需要3秒换弹夹
  （2）每次射击后需要随机调整1-3秒才能开下一枪
"""
# import random,time
# class Gun():
#     def __init__(self,name,bullet=10):
#         self.name = name
#         self.bullet = bullet
#     def shoot(self):
#         if self.bullet > 0:
#             self.bullet -= 1
#     def change(self):
#         self.bullet = 10
#
# class Soldier(object):
#     def __init__(self, name,gun):
#         self.name = name
#         self.count = 0  # 射击次数
#         self.score = 0  # 总成绩
#         self.result = 0  # 每次射击的成绩
#         self.gun = gun  # 枪类对象
#     def shoot(self):
#         if self.gun.bullet > 0:
#             self.gun.shoot()  # 调用枪类射击方法
#             self.count += 1
#             self.result = random.randint(8,10)  # 本次射击成绩
#             self.score += self.result  # 更新总成绩
#             print(f'射击次数: {self.count:2}\t成绩: {self.result}')
#             time.sleep(random.randint(1,3))
#         else:
#             print('--------更接弹夹--------')
#             self.add()
#     def add(self):
#         self.gun.change()
#         time.sleep(3)
#
# if __name__ =='__main__':
#     gun = Gun('AK47')
#     soldier = Soldier("顺溜",gun)
#     start = time.time()
#     print('---------训练开始---------')
#     while time.time()-start<=60:
#         soldier.shoot()
#     print('---------训练结束--------')
#     print(f"姓名: {soldier.name}\t射击次数: {soldier.count}\t总成绩:{soldier.score}")


"""
8.玩家与怪物
  （1）系统生成一个怪物（怪物的名称，血量，攻击值，防御值，攻击方法）Health, attack, defense
  （2）生成一个玩家（姓名，血量，攻击值，防御值，攻击方法）
  （3）系统角色和玩家的属性都由系统随机生成
       血量：2000-3500之间
       攻击：300-450之间
       防御：150-250之间
   （4）对战开始后玩家先手攻击，怪物掉血（玩家攻击值-怪物防御值）
   （5）怪物攻击，玩家掉血（怪物攻击值-玩家防御值）
   （6）任意一方血量为0则对战结束
"""
# import random,time
# class Role(object):
#     def __init__(self,name,skills):
#         self.name = name
#         self.skills = skills
#         self.health = random.randint(2000,3500)
#     def attack(self):
#         attack_name = random.choice(self.skills)
#         attack_power = random.randint(300, 450)
#         print(f"{self.name} 使用了技能 {attack_name},攻击力 {attack_power}")
#         return attack_power
#     def defense(self,hurt):
#         defense = random.randint(150, 250)
#         self.old_health = self.health
#         self.health = self.old_health + defense - hurt
#         print(f'{self.name} 受到{self.old_health-self.health}点真实伤害，剩余血量{self.health}')
#
# class Game(object):
#     def __init__(self,player,monster):
#         self.player = player
#         self.monster = monster
#
#     def start(self):
#         count = 0
#         while self.player.health > 0 and self.monster.health > 0:
#             count += 1
#             print(f"第 {count} 次对决".center(100, "-"))
#             if self.player.health > 0:
#                 hurt = self.player.attack()
#                 self.monster.defense(hurt)
#             else:
#                 break
#             print('VS'.center(10,'-'))
#             if self.monster.health>0:
#                 hurt = self.monster.attack()
#                 self.player.defense(hurt)
#             else:
#                 break
#             time.sleep(1)  # 等待一秒，发动下一次攻击
#         if self.player.health > 0:
#             print(f'{self.player.name}胜利！')
#         else:
#             print(f'{self.monster.name}胜利！')
#
# if __name__ == '__main__':
#     player = Role("唐三",["缠绕","寄生","蛛网束缚","蓝银囚笼"])
#     monster = Role("人面魔蜘",["蛛网","神经性剧毒","精神力刺伤"])
#     g = Game(player, monster)
#     g.start()

